class VegasController < ApplicationController
  
  def index
    
  end

  def ops
    if [6, 9].include?(params[:id].to_i)
      params[:id] = 2
    end
  end
  
  def xml
    render :xml => eval("xml_#{params[:id]}")
  end

  #part2,6,9: normal list
  def xml_2
    list1 = params[:ops][:list1].to_i
    list2 = params[:ops][:list2].to_i
    if list1 > list2
      listmp = list1
      list1 = list2
      list2 = listmp
    end
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => YAML.load(params[:ops][:yml])}) do |vvm|
     vvm.list1 list1..list2
    end
  end

  #part4: pickup
  def xml_4
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => YAML.load(params[:ops][:yml]).merge(params[:ops])}) do |vvm|
      vvm.pickup 1..params[:ops]['pickup_count'].to_i
    end
  end

  #part7: 榜外推荐
  def xml_7
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => YAML.load(params[:ops][:yml])}) do |vvm|
      vvm.play_bgm('bilibili-mubox.wav') do
        vvm.pics "rest", [1], :length => 4
      end
     vvm.list1 params[:ops][:rank_ary].delete_if{|a| a.blank?}.collect{|a| a.to_i}.reverse
    end
  end

  #part10: 历史
  def xml_10
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => YAML.load(params[:ops][:yml])}) do |vvm|
      vvm.play_bgm('1.mp3') do
        vvm.pics('weekly', [1], :length => params[:ops][:weekly_length] || 6)
        vvm.pics "history", [1], :length => 6
      end
      vvm.history
    end
  end

  #part11: 前三
  def xml_11
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => YAML.load(params[:ops][:yml])}) do |vvm|
     vvm.vvmtime.add_s 1
     vvm.list3.logo
    end
  end
  
  #part13: ed list
  def xml_13
    BiliRankingMaker.create({:path => params[:ops][:propath], :ops => {:ed_bgm => params[:ops]}}) do |vvm|
      vvm.ed_bgm do |length|
        vvm.ut[:pic_list] = VegasVideoTime.nl length - 21 if length > 21 #这句计算出每张排名图片停留的时间
        vvm.title(5, false, 5).list2.ed
      end
    end
  end
end
